package conMgr.model.tests;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import junit.framework.TestCase;

import org.junit.Test;

import conMgr.model.Conference;
import conMgr.model.Paper;
import conMgr.model.Review;
import conMgr.model.User;
import conMgr.model.UserType;
import conMgr.util.ObservableList;

public class UserTest extends TestCase{

	@Test
	public void testUser() {
		String name = "Vladimir";
		String email = "email@gmail.com";
		UserType type = UserType.AUTHOR;
		
		User user = new User(name, email, type);
		
		//test getName
		assertNotNull(user.getName());
		
		//test getEmail
		assertNotNull(user.getEmail());
		
		//test getType
		assertNotNull(user.getType());
		
		assertNotNull(user);
		
		//test for setCurrentUser
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.ADMIN);
		User.setCurrentUser(user_1);
		assertEquals(user_1, User.getCurrentUser());
		
		//test getCurrentUser
		assertNotNull(User.getCurrentUser());
		
		
	}
	
	@Test
	public void testGetAllUsers() {
		User.getAllUsers().clear();
		
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.ADMIN);
		//User user_2 = new User("Mike", "Mike@mail.ru", UserType.AUTHOR);
		//User user_3 = new User("Anna", "Anna@mail.ru", UserType.PROGRAM_CHAIR);
/*		ObservableList<User> list = new ObservableList<User>();
		list.add(user_1);
		list.add(user_2);
		list.add(user_3);*/
		
		//assertNotNull(list);	
		assertEquals(user_1,User.getAllUsers().get(0));
	}
	
	@Test
	public void testGetReivewerConferences() throws ParseException{
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.REVIEWER);
		ObservableList<Conference> list = user_1.getReivewerConferences();
		assertNotNull(list);
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		user_1.getReivewerConferences().add(conf_1);
		assertEquals(1, user_1.getReivewerConferences().size());
		assertEquals(conf_1, user_1.getReivewerConferences().get(0));
	}
	
	@Test
	public void testGetSubprogramChairConferences() throws ParseException{
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.SUBPROGRAM_CHAIR);
		ObservableList<Conference> list = user_1.getSubprogramChairConferences();
		assertNotNull(list);
		
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);	
		user_1.getSubprogramChairConferences().add(conf_1);
		assertEquals(1, user_1.getSubprogramChairConferences().size());
		assertEquals(conf_1, user_1.getSubprogramChairConferences().get(0));
	}
	
	@Test
	public void testGetProgramChairConferences() throws ParseException{
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.PROGRAM_CHAIR);
		ObservableList<Conference> list = user_1.getProgramChairConferences();
		assertNotNull(list);
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
	
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		user_1.getProgramChairConferences().add(conf_1);
		assertEquals(2, user_1.getProgramChairConferences().size());
		assertEquals(conf_1, user_1.getProgramChairConferences().get(0));
	}
	
	@Test
	public void testGetAuthorPapers() throws ParseException{
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.AUTHOR);
		ObservableList<Paper> list = user_1.getAuthorPapers();
		assertNotNull(list);
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		Paper paper_1 = new Paper("Paper 1", user_1, conf_1, null, null, null, null);
		user_1.getAuthorPapers().add(paper_1);
		assertEquals(2, user_1.getAuthorPapers().size());
		assertEquals(paper_1, user_1.getAuthorPapers().get(1));
	}
	
	@Test
	public void testGetSuprogramChairPapers() throws ParseException{
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.SUBPROGRAM_CHAIR);
		ObservableList<Paper> list = user_1.getSuprogramChairPapers();
		assertNotNull(list);
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		Paper paper_1 = new Paper("Paper 1", user_1, conf_1, null, null, null, null);
		user_1.getSuprogramChairPapers().add(paper_1);
		assertEquals(1, user_1.getSuprogramChairPapers().size());
		assertEquals(paper_1, user_1.getSuprogramChairPapers().get(0));
	}
	
	@Test
	public void testGetUserReviews() throws ParseException{
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.REVIEWER);
		ObservableList<Review> list = user_1.getUserReviews();
		assertNotNull(list);
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		Paper paper_1 = new Paper("Paper 1", user_1, conf_1, null, null, null, null);
		Review rev_1 = new Review(user_1,paper_1);
		user_1.getUserReviews().add(rev_1);
		assertEquals(2, user_1.getUserReviews().size());
		assertEquals(rev_1, user_1.getUserReviews().get(1));
		
		
	}
	

}
